package cn.doitedu.vueapi.dao.tg;


import cn.doitedu.vueapi.utils.TypeCastUtil;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import cn.doitedu.vueapi.pojo.tg.AdGenRec;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;


@Component
public interface AdGenRecMapper{

	@SelectProvider(type = SqlProvider.class, method = "selectByAdGenRec")
	@ResultMap("BaseResultMap")
	List<AdGenRec> selectByAdGenRec(AdGenRec adGenRec);

	@InsertProvider(type = SqlProvider.class,method = "insertAdGenRec")
	int insertAdGenRec(AdGenRec adGenRec);

	@UpdateProvider(type = SqlProvider.class,method = "updateAdGenRec")
	int updateAdGenRec(AdGenRec adGenRec);

	@DeleteProvider(type = SqlProvider.class,method = "deleteAdGenRec")
	int deleteAdGenRec(AdGenRec adGenRec);



	 class SqlProvider{
	
		public String selectByAdGenRec(AdGenRec adGenRec){
			SQL sql= new SQL().SELECT("*").FROM("`ad_gen_rec`");
			if(adGenRec.getId()!=null) sql.AND().WHERE("`id`="+adGenRec.getId());
			if(adGenRec.getAdid()!=null) sql.AND().WHERE("`adid`="+adGenRec.getAdid());
			if(adGenRec.getUid()!=null) sql.AND().WHERE("`uid`="+adGenRec.getUid());
			if(adGenRec.getPosImg()!=null) sql.AND().WHERE("`pos_img`='"+adGenRec.getPosImg()+"'");
			if(adGenRec.getCreateTime()!=null) sql.AND().WHERE("`create_time`='"+TypeCastUtil.date2SqlDatetime(adGenRec.getCreateTime())+"'");
	
			return sql.toString();
		}
		public String insertAdGenRec(AdGenRec adGenRec){
			SQL sql= new SQL().INSERT_INTO("`ad_gen_rec`");
			if(adGenRec.getId()!=null) sql.VALUES("`id`",String.valueOf(adGenRec.getId()));
			if(adGenRec.getAdid()!=null) sql.VALUES("`adid`",String.valueOf(adGenRec.getAdid()));
			if(adGenRec.getUid()!=null) sql.VALUES("`uid`",String.valueOf(adGenRec.getUid()));
			if(adGenRec.getPosImg()!=null) sql.VALUES("`pos_img`","'"+adGenRec.getPosImg()+"'");
			if(adGenRec.getCreateTime()!=null) sql.VALUES("`create_time`", "'"+TypeCastUtil.date2SqlDatetime(adGenRec.getCreateTime())+"'");
			return sql.toString();	
		}
		public String updateAdGenRec(AdGenRec adGenRec){
			SQL sql= new SQL().UPDATE("`ad_gen_rec`");
			if(adGenRec.getId()!=null) sql.SET("`id`=" + adGenRec.getId());
			if(adGenRec.getAdid()!=null) sql.SET("`adid`=" + adGenRec.getAdid());
			if(adGenRec.getUid()!=null) sql.SET("`uid`=" + adGenRec.getUid());
			if(adGenRec.getPosImg()!=null) sql.SET("`pos_img`='" + adGenRec.getPosImg()+"'");
			if(adGenRec.getCreateTime()!=null) sql.SET("`create_time`=" + adGenRec.getCreateTime());
			sql.WHERE("`id`="+adGenRec.getId());
			return sql.toString();	
		}
		public String deleteAdGenRec(AdGenRec adGenRec){
			SQL sql= new SQL().DELETE_FROM("`ad_gen_rec`");
			if(adGenRec.getId()!=null) sql.AND().WHERE("`id`=" + adGenRec.getId());
			if(adGenRec.getAdid()!=null) sql.AND().WHERE("`adid`=" + adGenRec.getAdid());
			if(adGenRec.getUid()!=null) sql.AND().WHERE("`uid`=" + adGenRec.getUid());
			if(adGenRec.getPosImg()!=null) sql.AND().WHERE("`pos_img`='" + adGenRec.getPosImg()+"'");
			if(adGenRec.getCreateTime()!=null) sql.AND().WHERE("`create_time`=" + adGenRec.getCreateTime());
			return sql.toString();	
		}
	}
	
}